package com.mew.common.dc.db;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mew.common.config.RedisConstantValue;
import com.mew.common.dc.mapper.FishingFishMapper;
import com.mew.common.dc.mapper.FishingQmcsMapper;
import com.mew.common.enm.DataStateType;
import com.mew.common.entity.config.FishingFish;
import com.mew.common.entity.config.FishingQmcs;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class FishingConfigService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private FishingFishMapper fishingFishMapper;
    @Autowired
    private FishingQmcsMapper fishingQmcsMapper;


    public void loadFish(){
        redisTemplate.delete(RedisConstantValue.CONFIG_FISHING_FISH);

        LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<FishingFish>()
                .eq(FishingFish::getState, DataStateType.Active.code());
        List<FishingFish> list = fishingFishMapper.selectList(queryWrapper);

        if (null == list || list.isEmpty()){
            return;
        }
        list.forEach(f -> redisTemplate.opsForList().leftPush(RedisConstantValue.CONFIG_FISHING_FISH, f));
    }

    public void lodeQmcs(){
        redisTemplate.delete(RedisConstantValue.CONFIG_FISHING_QMCS);

        LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<FishingQmcs>()
                .eq(FishingQmcs::getState, DataStateType.Active.code());
        List<FishingQmcs> list = fishingQmcsMapper.selectList(queryWrapper);

        if (null == list || list.isEmpty()){
            return;
        }
        list.forEach(f -> redisTemplate.opsForList().leftPush(RedisConstantValue.CONFIG_FISHING_QMCS, f));
    }


}
